package com.guigu.service.impl.manufacture;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.manufacture.MProcedureModulingMapper;
import com.guigu.pojo.manufacture.MProcedureModuling;
import com.guigu.service.manufacture.MProcedureModulingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-06
 */
@Service
public class MProcedureModulingServiceImpl extends ServiceImpl<MProcedureModulingMapper, MProcedureModuling> implements MProcedureModulingService {

    @Autowired
    private MProcedureModulingMapper mProcedureModulingMapper;

    @Override
    public BigDecimal selectModuleSubtotalByProcedureId(Integer id) {
        QueryWrapper<MProcedureModuling> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PARENT_ID",id);
        List<MProcedureModuling> list = mProcedureModulingMapper.selectList(queryWrapper);
        BigDecimal sum = new BigDecimal(0);
        for (MProcedureModuling mProcedureModuling : list) {
            sum = sum.add(mProcedureModuling.getSubtotal());
        }
        return sum;
    }

    @Override
    public ArrayList<MProcedureModuling> getProcedureModulingByParentId(Integer id) {
        QueryWrapper<MProcedureModuling> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PARENT_ID",id);
        queryWrapper.orderByAsc("DETAILS_NUMBER");
        ArrayList<MProcedureModuling> mProcedureModulings = (ArrayList<MProcedureModuling>) mProcedureModulingMapper.selectList(queryWrapper);
        return mProcedureModulings;
    }
}
